home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / waitforchild.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  993b  |  40 lines

  1. #include "kiss.h"
  2.  
  3. static void reportstatus (char *childname, int status, int background)
  4. {
  5.     if (WIFEXITED (status))
  6.     laststatus = WEXITSTATUS (status);
  7.     else if (WIFSIGNALED (status) && !background)
  8.     warning ("%s got signalled with sig %d", childname,
  9.          WTERMSIG (status));
  10.     else if (WCOREDUMP (status))
  11.     warning ("%s dumped core", childname);
  12.     else if (WIFSTOPPED (status))
  13.     warning ("%s stopped due to sig %d",
  14.          childname,  WSTOPSIG (status));
  15. }
  16.  
  17. void waitforchild (char *childname, int pid, int background)
  18. {
  19.     int
  20.     status;
  21.     char
  22.     buf [LINELEN];
  23.  
  24.     lastchildpid = pid;
  25.     
  26.     if (background)
  27.     printf ("[%d]\n", pid);
  28.  
  29.     /* let's see how this child is doing */
  30.     if (waitpid (pid, &status, background ? WNOHANG : 0) != -1)
  31.     reportstatus (childname, status, background);
  32.     
  33.     /* let's see how generic kids are doing */
  34.     while ( (pid = waitpid (WAIT_ANY, &status, WNOHANG)) > 0 )
  35.     {
  36.     sprintf (buf, "pid %d", pid);
  37.     reportstatus (buf, status, 1);
  38.     }
  39. }
  40.